<!-- 创建需求 -->
<template>
  <div>
    <el-dialog
      title="添加需求"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <el-form label-position="top" label-width="80px" :model="demandForm" style="padding-right: 50px; padding-left: 40px;">
        <el-form-item label="名称">
          <el-input v-model="demandForm.name" />
        </el-form-item>
        <el-form-item label="负责人">
          <el-input v-model="demandForm.personInCharge" />
        </el-form-item>
        <el-form-item label="成员">
          <el-input v-model="demandForm.member" />
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="demandForm.remark" type="textarea" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="createVemand">立即创建</el-button>
          <el-button @click="dialogVisible = false">取消</el-button>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer" />
    </el-dialog>
  </div>
</template>

<script>
import { create } from '@/api/auto/demand.js'
export default {
  data() {
    return {
      dialogVisible: false,
      demandForm: {}
    }
  },
  methods: {
    init(id) {
      this.dialogVisible = true
      this.demandForm.productId = id
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => { done() })
        .catch(_ => {})
    },
    createVemand() {
      create(this.demandForm).then(respnose => {
        if (respnose && respnose.code === 200) {
          this.$message.success(respnose.message)
          this.dialogVisible = false
          this.$emit('refreshDataList')
        } else {
          this.$message.error(respnose.message)
        }
      })
    }
  }
}
</script>

<style>
</style>
